<template>
    <div class="table">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-lx-cascades"></i> 大师管理</el-breadcrumb-item>
                <el-breadcrumb-item>大师列表</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <!-- <el-button type="primary" icon="el-icon-delete" class="handle-del mr10" @click="delAll">批量</el-button> -->
                <el-input v-model="select_word" placeholder="筛选关键词" class="handle-input mr10" @change="refresh"></el-input>
                <el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button>
            </div>
            <el-table :data="coachData" border class="table" ref="multipleTable" @selection-change="handleSelectionChange">
                <!-- <el-table-column type="selection" width="55" align="center"></el-table-column> -->
                <el-table-column type="index" width="80" align="center" label="序号" sortable="true"></el-table-column>
                <el-table-column label="头像" width="90">
                    <template slot-scope="scope">
                        <el-image style="width: 60px; height: 60px" fit="cover"
                            :src="`http://localhost/fitness/public/static/img/`+scope.row.avatar"
                            @click="handlePictureCardPreview(scope.row.avatar)">
                            <div slot="error" class="image-slot">
                                <i class="el-icon-picture-outline"></i>
                            </div>
                        </el-image>
                    </template>
                </el-table-column>                
                <el-table-column prop="coachname" label="大师姓名" width="120">
                </el-table-column>
                <el-table-column prop="clubname" label="所属俱乐部" width="200">
                </el-table-column>
                <el-table-column prop="area" label="大师领域" width="180">
                </el-table-column>
                <el-table-column label="大师性别" width="120">
                    <template slot-scope="scope">
                        {{scope.row.sex===1?'男':'女'}}
                    </template>
                </el-table-column>
                <el-table-column prop="cemail" label="邮箱地址" width="auto">
                </el-table-column>
                <el-table-column prop="ctel" label="电话号码" width="120">
                </el-table-column>
                <el-table-column prop="masterdate" label="通过日期" sortable width="200">
                </el-table-column>
                <el-table-column prop="tel" label="状态" width="90" align="center">
                    <template slot-scope="scope">
                        <el-tooltip class="item" effect="dark" :content="'审核人：'+scope.row.adminname" placement="top">
                            <i class="el-icon-circle-check" style="color:#9b59b6"> 大师</i>
                        </el-tooltip>
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="120" align="center">
                    <template slot-scope="scope">
                        <el-button type="text" icon="el-icon-delete" class="red" @click="handleCancel(scope.row)">取消大师</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <!-- 取消教练提示框 -->
        <el-dialog title="提示" :visible.sync="cancelVisible" width="300px" center>
            <div class="del-dialog-cnt">取消大师不可恢复，是否确定取消改名大师？</div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="cancelVisible = false">取 消</el-button>
                <el-button type="primary" @click="confirmCancel">确 定</el-button>
            </span>
        </el-dialog>

        <!-- 预览图弹出框 -->
        <el-dialog :visible.sync="dialogImgVisible" width="25%">
            <img width="100%" :src="dialogImageUrl" alt="">
        </el-dialog>
    </div>
</template>

<script>

    export default {
        name: 'basetable',
        data() {
            return {
                coachData: [],
                multipleSelection: [],
                select_word: '',
                is_search: false,
                cancelVisible: false,
                cancelId: 0,
                dialogImageUrl: '',
                dialogImgVisible: false
            }
        },
        created() {
            this.getData();
        },
        methods: {
            getData() {
                this.$axios('/api/Coach/masterList').then(res => {
                    // console.log('res.data :', res.data);
                    this.coachData = res.data;
                })
            },
            search() {
                setTimeout(() => {
                    this.coachData = this.coachData.filter((d) => {
                        if(d.coachname.indexOf(this.select_word) > -1){
                            return d;
                        }
                    })
                }, 500);
            },
            refresh(){
                this.getData();
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            handleCancel(row){
                this.cancelVisible = true;
                this.cancelId = row.coachid;
            },
            cancelMaster(coachid){
                this.$axios.get('/api/Coach/cancelMaster',{
                    params: {
                        coachid: coachid
                    }
                }).then(res => {
                    if(res.data===1){
                        this.$message({
                            showClose: true,
                            message: '取消成功',
                            type: 'success'
                        });
                        this.getData();
                    }
                });

            },
            confirmCancel(){
                this.cancelMaster(this.cancelId);
                this.cancelVisible = false;
            },
            handlePictureCardPreview(url) {
                this.dialogImageUrl =`http://localhost/fitness/public/static/img/`+url;
                this.dialogImgVisible = true;
            },
        }
    }

</script>

<style scoped>
    .handle-box {
        margin-bottom: 20px;
    }

    .handle-select {
        width: 120px;
    }

    .handle-input {
        width: 300px;
        display: inline-block;
    }
    .del-dialog-cnt{
        font-size: 16px;
        text-align: center
    }
    .table{
        width: 100%;
        font-size: 14px;
    }
    .red{
        color: #ff0000;
    }
    .mr10{
        margin-right: 10px;
    }
</style>
